package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsIssue;
import com.qf.pojo.DtsOrder;
import com.qf.service.DtsIssueService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/admin/issue")
public class DtsAdminIssueController {


    @Autowired
    DtsIssueService issueService;


    @RequestMapping("/delete")
    public Object delete(@RequestBody DtsIssue issue){
        issueService.delete(issue);
        return ResponseUtil.ok();
    }

    @RequestMapping("/update")
    public Object update(@RequestBody DtsIssue issue){
        DtsIssue issue1=issueService.update(issue);
        return ResponseUtil.ok(issue1);
    }

    @RequestMapping("/create")
    public Object create(@RequestBody DtsIssue issue){
        DtsIssue issue1=issueService.add(issue);
        return ResponseUtil.ok(issue1);
    }
    @RequestMapping("/list")
    public Object list(@RequestParam(name = "page",required = false,defaultValue = "1") Integer page,
                       @RequestParam(name = "limit",required = false,defaultValue = "20")Integer limit,
                       String sort, String order, String question){
        IPage<DtsIssue> iPage =issueService.findByPage(page,limit,sort,order,question);
        Map<String,Object> data = new HashMap<>();
        data.put("total",iPage.getTotal());
        data.put("items",iPage.getRecords());
        return ResponseUtil.ok(data);
    }
}
